<?php
/**
 * @name IndexController
 * @author box-e470\qiph
 * @desc 默认控制器
 * @see http://www.php.net/manual/en/class.yaf-controller-abstract.php
 */
class IndexController extends \Yaf\Controller_Abstract {

	/**
     * 默认动作
     * Yaf支持直接把Yaf_Request_Abstract::getParam()得到的同名参数作为Action的形参
     * 对于如下的例子, 当访问http://yourhost/FirstProject/index/index/index/name/box-e470\qiph 的时候, 你就会发现不同
     */
	public function indexAction() {
	    session_start();

        //     获取id，title，content，tags，updated_at,
        $arrs = ArticleModel::orderBy('created_at','desc')->take(2)->get()->toArray();

        $arr1 = $arrs[0];
        $aid1 = $arr1['aId'];
        $title1 = $arr1['title'];
        $content1 = $arr1['content'];
//        用户id
        $uid1 = $arr1['uid'];
        $username1 = UsersModel::where('Id','=',$uid1)->select('username')->get();
        if (count($username1)>0){
            $u = json_decode($username1,true);
            $name1 = $u[0]['username'];
        }

        $updated_at1 = $arr1['updated_at'];
        $updated_at1 =  date("Y-m-d",strtotime( $updated_at1  ));
        $tags1 = $arr1['tags'];
        $tag1 ='';
        $t1 = explode('&',$tags1);
        for ($i = 0;$i<count($t1);$i++){
            $tag1 = $tag1.$t1[$i].'    ';
        }

        $arrays1 = array('id1'=>$aid1,'title1'=>$title1,'content1'=>$content1,'name1'=>$name1,'tags1'=>$tag1,'updated_at1'=>$updated_at1);
        $this->getView()->assign($arrays1);

        $arr2 =$arrs[1];
        $aid2 = $arr2['aId'];
        $title2 = $arr2['title'];
        $content2 = $arr2['content'];
        //        用户id
        $uid2 = $arr2['uid'];
        $username = UsersModel::where('Id','=',$uid2)->select('username')->get();
        if (count($username)>0){
            $u = json_decode($username,true);
            $name2 = $u[0]['username'];
        }
        $updated_at2 = $arr2['updated_at'];
        $updated_at2 =  date("Y-m-d",strtotime( $updated_at2  ));
        $tags2 = $arr2['tags'];
        $tag2 ='';
        $t2 = explode('&',$tags2);
        for ($i = 0;$i<count($t2);$i++){
            $tag2 = $tag2.$t2[$i].'    ';
        }

        $arrays2 = array('id2'=>$aid2,'title2'=>$title2,'content2'=>$content2,'name2'=>$name2,'tags2'=>$tag2,'updated_at2'=>$updated_at2);
        $this->getView()->assign($arrays2);
	}
}
